	package com.mobjam.workingtitleforagame.UnitTests;

	import com.mobjam.workingtitleforagame.Character;
import com.mobjam.workingtitleforagame.StoreActivity;
	import com.mobjam.workingtitleforagame.R;
	import com.mobjam.workingtitleforagame.R.id;
	import com.mobjam.workingtitleforagame.R.layout;

	import android.app.Activity;
	import android.app.Instrumentation;
	import android.app.Instrumentation.ActivityMonitor;
	import android.test.ActivityInstrumentationTestCase2;
	import android.test.UiThreadTest;
	import android.view.KeyEvent;
	import android.view.View;
import android.widget.Button;
import android.widget.Gallery;

public class StoreActivityTest extends ActivityInstrumentationTestCase2<StoreActivity> {
		private Instrumentation storeInstrumentation;
		private StoreActivity storeActivity;
//		private Button button1;
//		private Button button2;
		private View storeLayout;
		private int gold;

		public StoreActivityTest() {
			super("com.mobjam.workingtitleforagame", StoreActivity.class);
		}

		protected void setUp() throws Exception {
			super.setUp();
			storeInstrumentation = getInstrumentation();
			storeActivity = getActivity();
			storeLayout = (View) storeActivity.findViewById(R.layout.activity_sale);
			gold = Character.getInstance().getGold();
		}

		protected void tearDown() throws Exception {
			super.tearDown();
		}

		@UiThreadTest
		public void testBuyButton() {
			
			final Gallery storeGalleryView = (Gallery) storeActivity.findViewById(R.id.gallery1);
			final Button buyButton = (Button) storeActivity.findViewById(R.id.button3);
			storeActivity.runOnUiThread(new Runnable() {

				@Override
				public void run() {
					// TODO Auto-generated method stub
					storeGalleryView.performItemClick(storeGalleryView, 0, 0);
					buyButton.performClick();
				}
			});
			
			if (gold !=0 ) {
				assertTrue(gold > Character.getInstance().getGold());
			}
		}		

		@UiThreadTest
		public void testCancelButton() {
			
			final Button cancelButton = (Button) storeActivity.findViewById(R.id.button4);
			storeActivity.runOnUiThread(new Runnable() {

				@Override
				public void run() {
					// TODO Auto-generated method stub
					cancelButton.performClick();
				}
			});

			assertTrue(true);
		}

		public void testDestroy() {
			storeActivity.finish();
			storeActivity = this.getActivity();
		}
}
